# 队列
from queue import Queue
import random
import time
import threading


# q = Queue(5)
# for i in range(4):
#     q.put(i)
# print("队列中数据", q.qsize())
# for _ in range(5):
#     try:
#         print(q.get(block=False))
#     except:
#         print("数据已经取完")
#         break
# if q.full():
#     print("队列已满")
# else:
#     print("队列不满")
# q2 = Queue(5)
# for i in range(6):
#     try:
#         q2.put(i, block=False)
#     except:
#         print("队列已满")
#         break
#
# print("程序结束")


def add_values(q):
    while True:
        q.put(random.randint(100, 1000))
        time.sleep(1)


def get_values(q):
    while True:
        print("取出元素：{}".format(q.get()))


def start():
    q = Queue(10)
    t1 = threading.Thread(target=add_values, args=(q,))
    t2 = threading.Thread(target=get_values, args=(q,))
    t1.start()
    t2.start()


if __name__ == '__main__':
    start()
